package com.gitee.huxing.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @Description:
 * @ProjectName: AlgorithmicPactice
 * @Package: com.gitee.huxing.proxy
 * @ClassName: MoneyCountInvocationHandler
 * @Author: huxing
 * @DateTime: 2022-04-01 2:05 PM
 */
public class MoneyCountInvocationHandler implements InvocationHandler {

    /** 被代理的对象 **/
    private final Object target;

    /** 内部存储的钱数 **/
    private Double moneyCount;

    public MoneyCountInvocationHandler(Object target) {
        this.target = target;
        this.moneyCount = 0.0;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        Object result = method.invoke(target, args);
        moneyCount += 0.07;
        System.out.println("发送短信成功，共花了：" + moneyCount + "元");
        return result;
    }
}
